package cn.com.nes.site.entity.em.crm.customer;

import cn.com.nes.common.exception.NoSuchEnumException;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 客户性质 枚举
 *  值域对应 t_param 表 param_type=20
 *
 * @Author: ShenWei
 * @Date: 2024/05/08/14:07
 */
@Slf4j
public enum CustomerNatureEnum {

    // 客户性质
    _personal("01","零售客户"),
    _dealer("02","经销商"),
    _manufacturer("03","设备厂家"),
    _government("04","政府客户"),
    PUBLIC_INSTITUTION("05","公共机构"),
    _enterprise("06","企业客户"),
    END_USRE_GOVERNMENT("07", "政府终端客户"),
    _other("999","其他"),

    ;

    CustomerNatureEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    private String key;

    private String value;

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public static CustomerNatureEnum getEnum(String key) {
        Map<String, CustomerNatureEnum> map = new HashMap<>();
        for (CustomerNatureEnum customerNatureEnum : values()) {
            map.put(customerNatureEnum.getKey(), customerNatureEnum);
        }
        if (!map.containsKey(key)) {
            throw new NoSuchEnumException("未匹配的客户性质");
        }
        return map.get(String.valueOf(key));
    }

    public static String enumConvertKeyToValue(String key) {
        String val = "";
        try {
            val = getEnum(key).getValue();
        } catch (NoSuchEnumException e) {
            log.warn("{}, convert key to value error, key:[{}], cause:[{}]", e.getStackTrace()[0].getFileName(), key, e.getMessage());
        }
        return val;
    }
}
